class ChildrenController < ApplicationController
  def index
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    @child_pages, @children = paginate :children, :per_page => 10
  end

  def show
    @child = Child.find(params[:id])
  end

  def new
    @child = Child.new
  end

  def create
    list
    render :action => 'list'
    # @child = Child.new(params[:child])
    # if @child.save
    #   flash[:notice] = 'Child was successfully created.'
    #   redirect_to :action => 'list'
    # else
    #   render :action => 'new'
    # end
  end

  def edit
    @child = Child.find(params[:id])
  end

  def update
    @child = Child.find(params[:id])
		@adults = Person.find(:conditions => { :is_parent? => "true" })
    if @child.update_attributes(params[:child])
      flash[:notice] = 'Child was successfully updated.'
      redirect_to :action => 'show', :id => @child
    else
      render :action => 'edit'
    end
  end

  def destroy
    Child.find(params[:id]).destroy
    redirect_to :action => 'list'
  end
end
